package cn.gcjxsc.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;


/**
 * @author pumbaa
 * @since 1.0
 */
@Configuration
public class DbConfig {

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    @Primary
    @RefreshScope
    public DataSourceProperties dataSourceProperties(){
        return new DataSourceProperties();
    }

    @Bean("dataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    @RefreshScope
    public HikariDataSource dataSource(DataSourceProperties dataSourceProperties){
       return (HikariDataSource)dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
    }
}
